package org.nowcoder.leetcode.DP;

/**
 * Title  : 70. Climbing Stairs
 * Source : https://leetcode.cn/problems/climbing-stairs/description/
 * Author : XrazYang
 * Date   : 2023-12-14
 */

public class LeetCode_70 {
    //线性动态规划
    public int climbStairs(int n) {
        if (n > 2) {
            int[] climb = new int[n + 1];
            climb[1] = 1;
            climb[2] = 2;

            for (int i = 3; i <= n; i++) {
                climb[i] = climb[i - 1] + climb[i - 2];
            }
            return climb[n];
        } else return n;
    }

    //递推公式
    public static int climStairsR(int n) {
        if (n <= 2) {
            return n;
        }
        return climStairsR(n - 1) + climStairsR(n - 2);
    }
}
